package com.dajie.pt.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhihaosong on 23/07/15.
 */
public class GetUrlDao {
    private static Logger logger = LoggerFactory.getLogger(GetUrlDao.class);

    public static Map getUrl() {
        Map<String, RedirectUrl> data = new HashMap<String, RedirectUrl>();
        Connection conn = null;
        Statement ps = null;
        ResultSet rs = null;
        String sql = "select id,pc_url,mobile_url,describe_url from tb_url_redirect";
        conn = DBUtil.getConnInstance();

        try {
            ps = conn.createStatement();
            rs = ps.executeQuery(sql);
            while (rs.next()) {
                RedirectUrl redirectUrl=new RedirectUrl();
                redirectUrl.setId(rs.getString("id"));
                redirectUrl.setPcUrl(rs.getString("pc_url"));
                redirectUrl.setMobileUrl(rs.getString("mobile_url"));
                data.put(rs.getString("id"),redirectUrl);
            }
            logger.info("getUrl --> map:{}", data.toString());
        } catch (SQLException e) {
            logger.info("getUrl --> SQLException:{}", e.getMessage());
            e.printStackTrace();
        }

        return data;
    }
}
